
var adminLogin= {};
//页面加载事件
$(function(){
    adminLogin.methods.Login(this);
});

adminLogin.data = {};
adminLogin.addEvent =function(obj){};
adminLogin.methods = {};
adminLogin.methods.Login=function(obj){
    $("#shop-btn-login").off("click").on("click",function(){
        var result = adminLogin.methods.valiData();
        if(!result){
            return;
        }
        //{ name:'ppm', pwd:'p@ssw0rd' }
        Controller.Ajax({
            url:router+"/admin/loginasync",
            type:"POST",
            dataType:"json",
            data:result,
            success:function(data){
                if(data.result!=0){
                    //登录失败，抛出异常信息
                    adminLogin.methods.showError(data.promptMsg)
                }else{
                    adminLogin.methods.hideError();
                    //记录cookie
                    adminLogin.methods.setCookie(result);
                    //成功动作,页面跳转
                    window.location.href = "../../adminTemplate/index.html";
                }
            }
        });
    });
}
adminLogin.methods.valiData=function(obj){
    var user = $("[name=user]").val().trim();
    var pwd = $("[name=pwd]").val().trim();
    if(!user||user==""){
        //用户名为空
        adminLogin.methods.showError("用户名为空");
        return null;
    }
    if(!pwd||pwd==""){
        adminLogin.methods.showError("登录密码为空");
        return null;
    }else{
        if(pwd.length<6){
            adminLogin.methods.showError("登录密码不得少于六位");
            return null;
        }
    }
    return {"name":user,"pwd":pwd};
}
adminLogin.methods.setCookie=function(obj){
    var remember = $("#shop-remember").is(":checked");
    if(remember){
        //记录cookie
        Cookie.setCookie("shopUserName",obj.name,3);
        Cookie.setCookie("shopUserPwd",obj.pwd,3);
    }
}
adminLogin.methods.showError=function(str){
    $(".shop-erro-tips").text(str);
    $(".shop-erro-tips").addClass("shop-active");
}
adminLogin.methods.hideError=function(str){
    $(".shop-erro-tips").text("");
    $(".shop-erro-tips").removeClass("shop-active");
}